/*
 * @Author: 来自火星的码农 15122322+heyzhi@user.noreply.gitee.com
 * @Date: 2025-06-25 09:20:30
 * @LastEditors: 来自火星的码农 15122322+heyzhi@user.noreply.gitee.com
 * @LastEditTime: 2025-06-25 15:18:37
 * @FilePath: /server/workspace/tests/test_thread.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include"../src/base/thread.h"
#include"../src/base/config.h"
#include"../src/base/Log.h"
#include"../src/base/mutex.h"
static Yizhi::Logger::ptr logger=SERVER_LOG_NAME("system");

Yizhi::Mutex m_mutex;
int count=0;
void func1(){
    
    SERVER_LOG_DEBUG(logger)<<"hello\t"<<Yizhi::Thread::getName()<<"\tid:"<<Yizhi::GetThreadid();
}
void func2(int &x){
    for(int i=0;i<100000;i++){
        Yizhi::Mutex::Lock lock(m_mutex);
        count++;
    }
}
int main(){
    SERVER_LOG_DEBUG(logger)<<"thread test begin"<<Yizhi::GetThreadid();
    std::vector<Yizhi::Thread::ptr> thr;
    thr.resize(5);
    int res=0;
    for(int i=0;i<5;i++){
        thr[i].reset(new Yizhi::Thread(std::bind(func2,res),"test_"+std::to_string(i)));
    }

    for(auto &i:thr){
        i->join();
    }
    SERVER_LOG_DEBUG(logger)<<count;
    SERVER_LOG_DEBUG(logger)<<"thread test end";

}